home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / pmode / pmode386 / example0.asm < prev    next >
Encoding:
Assembly Source File  |  1993-05-29  |  5.7 KB  |  168 lines

  1. ; PMODE example program #0.
  2. ; Load up a mouse driver, uncomment the mouse calls, compile, and run.
  3. ; When run, use the left mouse button to draw. Any key exits.
  4.  
  5.         .386p
  6.         jumps
  7. code16  segment para public use16
  8.         assume cs:code16, ds:code16
  9.  
  10. ;─────────────────────────────────────────────────────────────────────────────
  11. rmr:                                    ; real mode mouse callback
  12.         nop
  13.         mov byte ptr rmr,0cbh           ; NOP to RETF, dont want reentry here
  14.                                         ;  this is real mode, CS write allowed
  15.         push ds edx
  16.         push cs
  17.         pop ds
  18.         push ds:v86r_bx                 ; save these, remember this is an IRQ
  19.                                         ;  callback
  20.         push ds:v86r_ecx
  21.         push ds:v86r_edx
  22.         mov ds:v86r_bx,bx
  23.         mov ds:v86r_cx,cx
  24.         mov ds:v86r_dx,dx
  25.         mov edx,offset pmr              ; call protected mode mouse handler
  26.         int 32h
  27.         pop ds:v86r_edx
  28.         pop ds:v86r_ecx
  29.         pop ds:v86r_bx
  30.         pop edx ds
  31.         mov byte ptr cs:rmr,90h         ; RETF back to NOP
  32.         retf
  33.  
  34. code16  ends
  35.  
  36. code32  segment para public use32
  37.         assume cs:code32, ds:code32
  38.  
  39. include pmode.inc
  40. include file.inc
  41.  
  42. public  _main
  43.  
  44. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  45. ; DATA
  46. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  47. systypestr      db      'raw ','XMS ','VCPI','DPMI'
  48. filename        db      'pmode.asm',0
  49.  
  50. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  51. ; CODE
  52. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  53.  
  54. ;─────────────────────────────────────────────────────────────────────────────
  55. pmr:                                    ; protected mode mouse handler
  56.         test bx,1                       ; skip if left button not pressed
  57.         jz _ret
  58.         push ax                         ; save this, (V86_AX wasn't saved in
  59.                                         ;  real mode)
  60.         mov al,33h
  61.         mov v86r_ax,2                   ; don't have to save this since it is
  62.                                         ;  already stored in AX on the stack,
  63.                                         ;  and will be restored to that on RET
  64.         int 33h                         ; hide mouse cursor
  65.         movzx ecx,cx                    ; calculate and plot box
  66.         shr ecx,3
  67.         movzx edx,dx
  68.         shr edx,3
  69.         lea edx,[edx*4+edx]
  70.         shl edx,5
  71.         lea edx,[edx+ecx*2]
  72.         mov word ptr gs:[0b8000h+edx],7dbh
  73.         mov al,33h                      ; restore mouse
  74.         mov v86r_ax,1
  75.         int 33h
  76.         pop ax
  77.         ret                             ; back to real mode
  78. ;─────────────────────────────────────────────────────────────────────────────
  79. setupmouse:                             ; mouse on, and setup callback
  80.         mov al,33h
  81.         mov v86r_ax,0
  82.         int 33h
  83.         mov v86r_ax,1
  84.         int 33h
  85.         mov v86r_ax,0ch
  86.         mov v86r_cx,3
  87.         mov v86r_dx,offset rmr
  88.         mov v86r_es,code16
  89.         int 33h
  90.         ret
  91. ;─────────────────────────────────────────────────────────────────────────────
  92. resetmouse:                             ; bye-bye mousey
  93.         mov al,33h
  94.         mov v86r_ax,0
  95.         int 33h
  96.         ret
  97. ;─────────────────────────────────────────────────────────────────────────────
  98. putcrap:                                ; put some crap to screen with attr AH
  99.         lodsb
  100.         stosw
  101.         loop putcrap
  102.         ret
  103.  
  104. ;═════════════════════════════════════════════════════════════════════════════
  105. _main:
  106.         sti
  107.         @rlp edi,0b8000h                ; get relative pointer to text screen
  108.         mov ecx,(80*25)/2               ;  and fill with something
  109.         mov eax,8b008b0h
  110.         rep stosd
  111.  
  112.         @rlp edi,0b8000h+162            ; put type of system
  113.         movzx esi,_sysbyte0
  114.         and esi,3                       ; all the other bits will be 0, but
  115.         lea esi,[esi*4+systypestr]      ;  what the hell
  116.         mov ecx,4
  117.         mov ah,7
  118.         call putcrap
  119.  
  120.         mov eax,12*80                   ; allocate low mem buffer for l8r
  121.         call _getlomem
  122.         jc filedone                     ; skip if not enough mem for buffer
  123.         mov ebp,eax
  124.         mov esi,eax
  125.         mov eax,offset filename         ; convert filename offset to seg:off
  126.         add eax,_code32a                ;  for DOS
  127.         shld ebx,eax,28
  128.         and ax,0fh
  129.         mov v86r_ds,bx
  130.         mov v86r_dx,ax
  131.         mov v86r_ax,3d00h               ; open file
  132.         mov al,21h
  133.         int 33h
  134.         jc filedone                     ; skip if error
  135.         mov ax,v86r_ax                  ; transfer handle for read
  136.         mov v86r_bx,ax
  137.         add ebp,_code32a                ; adjust 32bit offset to real addx
  138.         shld ebx,ebp,28                 ; buffer to real mode seg:off
  139.         and bp,0fh
  140.         mov v86r_ds,bx
  141.         mov v86r_dx,bp
  142.         mov v86r_cx,12*80
  143.         mov v86r_ah,3fh                 ; read into low mem buffer
  144.         mov al,21h
  145.         int 33h
  146.         mov v86r_ah,3eh                 ; close file
  147.         int 33h
  148.         @rlp edi,0b8000h+(13*160)
  149.         mov ecx,12*80
  150.         mov ah,8                        ; put to low half of screen
  151.         call putcrap
  152. filedone:
  153.  
  154. ;       call setupmouse                 ; uncomment this if you want mousey
  155.  
  156.         mov v86r_ah,0                   ; wait for a key using BIOS
  157.         mov al,16h
  158.         int 33h
  159.  
  160. ;       call resetmouse                 ; uncomment this if you want mousey
  161.  
  162.         jmp _exit
  163.  
  164.  
  165. code32  ends
  166.         end
  167.  
  168.